package com.bawei.mall.user.controller;

import com.bawei.common.core.domain.R;
import com.bawei.common.core.utils.StringUtils;
import com.bawei.common.core.web.controller.BaseController;
import com.bawei.common.core.web.page.TableDataInfo;
import com.bawei.common.security.service.TokenService;
import com.bawei.mall.user.domain.CusUser;
import com.bawei.mall.user.domain.CusUserCoupon;
import com.bawei.mall.user.domain.MallUserCollectInfo;
import com.bawei.mall.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName CusUserController
 * @Description 描述
 * @Author ZiZheng.Li
 * @Date 2024/6/28 9:51
 */
@RestController
@Api(tags = {"用户信息"})
public class CusUserController extends BaseController {
    @Autowired
    private UserService userService;

    @Autowired
    private TokenService tokenService;

    /**
     * 获取当前用户信息
     */
    @ApiOperation("获取当前用户信息")
    @GetMapping("/cusInfo/{username}")
    public R<CusUser> info(@PathVariable("username") String username)
    {

        CusUser cusUser = userService.selectUserByUserName(username);
        if (StringUtils.isNull(cusUser))
        {
            return R.fail("用户名或密码错误");
        }
        return R.ok(cusUser);
    }

    /**
     * 获取收藏信息
     */
    @ApiOperation("获取收藏信息")
    @GetMapping("/selectCollectInfos")
    public TableDataInfo selectCollectInfos(MallUserCollectInfo collect)
    {
        startPage();
        List<MallUserCollectInfo> list = userService.selectCollectProductBrandInfoList(collect);
        return getDataTable(list);
    }

    /**
     * 获取收藏信息
     */
    @ApiOperation("获取收藏信息")
    @GetMapping("/getAllCollectInfos")
    public R<List<MallUserCollectInfo>> getAllCollectInfos()
    {
        List<MallUserCollectInfo> list = userService.getAllCollectInfos();
        return R.ok(list);
    }

    /**
     * 清空收藏信息
     */
    @ApiOperation("清空收藏信息")
    @PostMapping("/clearCollectInfos")
    public R clearCollectInfos(@RequestBody List<Integer> productIds) {
        userService.clearCollectInfos(productIds);
        return R.ok();
    }

    /**
     * TODO 待优化 我的优惠券
     */
    @GetMapping("/selectCouponInfos")
    public TableDataInfo selectCouponInfos(String useStatus)
    {
        startPage();
        List<CusUserCoupon> list = userService.selectCouponInfos(useStatus);
        return getDataTable(list);
    }
}


